package com.upcode.weighing.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.upcode.weighing.base.controller.BaseController;
import com.upcode.weighing.common.Constants;
import com.upcode.weighing.domain.SysDictType;
import com.upcode.weighing.service.SysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


/**
 * @author liqi
 * @Description:
 * @date 2018/5/4/00415:47
 */
@RestController
@RequestMapping(value = "/dictType")
@Api(value = "/dictType",description = "字典类型接口",produces = MediaType.ALL_VALUE)
public class DictTypeController extends BaseController {

    @Autowired
    private SysDictTypeService sysDictTypeService;

//    @ApiOperation(value = "字典类型新增",notes ="")
//    @PostMapping(value = "/add")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="name",dataType = "String",paramType="query")
//    })
//    public Object add(String name){
//        boolean insert = sysDictTypeService.add(name);
//        if (insert){
//            return success("新增字典类型成功");
//        }
//        return error("新增字典类型失败");
//    }
//
//    @ApiOperation(value = "字典类型修改",notes ="")
//    @PostMapping(value = "/edit")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="id",dataType = "Long",paramType="query"),
//            @ApiImplicitParam(name="name",dataType = "String",paramType="query")
//    })
//    public Object edit(String name, Long id){
//        boolean update = sysDictTypeService.edit(name,id);
//        if (update){
//            return success("修改字典类型成功");
//        }
//        return error("修改字典类型失败");
//    }

    @ApiOperation(value = "删除字典类型",notes ="")
    @GetMapping(value = "/del/{id}")
    public Object del(@PathVariable("id") @NotNull(message = "字典类型ID不能为空") Long id){
        boolean del = sysDictTypeService.removeById(id);
        if (del){
            return success("删除字典类型成功");
        }
        return error("删除字典类型失败");
    }

    @ApiOperation(value = "全量字典类型",notes ="")
    @GetMapping(value = "/listAll")
    public Object listAll(){
        QueryWrapper<SysDictType> wrapper = new QueryWrapper<>();
        wrapper.eq("status", Constants.STATUS_NORMAL);
        wrapper.orderByDesc("create_time");
        return success(sysDictTypeService.list(wrapper));
    }

//    @ApiOperation(value = "字典类型分页列表",notes ="")
//    @PostMapping(value = "/list")
//    public Object list(@Validated @RequestBody ParamPageVo<SysDictTypeListVo> vo) {
//        Page<SysDictType> list = sysDictTypeService.list(vo);
//        return success(list);
//    }

    @ApiOperation(value = "字典类型详情",notes ="")
    @GetMapping(value = "/details/{id}")
    public Object details(@PathVariable("id") @NotNull(message = "字典类型ID不能为空") Long id){
        return success(sysDictTypeService.getById(id));
    }


}
